package com.leetcode.array_matrix;

/**
 * @author Dennis Li
 * @date 2020/10/25 17:51
 */
public class FindPoisonedDuration_495 {

    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int sum = 0;
        for (int i = 0; i < timeSeries.length; i++) {
            if (i == 0) {
                sum += duration;
            } else {
                int gap = timeSeries[i] - timeSeries[i - 1];
                sum += Math.min(gap, duration);
            }
        }
        return sum;
    }

}
